//
// Cursor.cpp for  in /home/gomes_m//svn/google/ticket-pour-gdl/menu_V1
// 
// Made by mickael gomes
// Login   <gomes_m@epitech.net>
// 
// Started on  Fri May 17 17:55:58 2013 mickael gomes
// Last update Wed May 22 12:39:43 2013 mickael gomes
//

#include		"Cursor.hh"

Cursor::Cursor()
{
  fptr_[B] = &Cursor::getBack;
  fptr_[UP] = &Cursor::moveUp;
  fptr_[DOWN] = &Cursor::moveDown;
  fptr_[LEFT] = &Cursor::moveLeft;
  fptr_[RIGHT] = &Cursor::moveRight;
  fptr_[RETURN] = &Cursor::setChoice;
  choice_ = 0;
}


Cursor::~Cursor()
{

}

void			Cursor::initialize(std::string const &path)
{
  cursor_.initialize(path, 0, 0, 0, 0, 0);
}

void			Cursor::moveUp()
{
  if (coord.moveY_ < 0)
    coord.moveY_ += coord.moveYValue_;
  else
    coord.moveY_ = coord.limitYValue_;
}

void			Cursor::moveDown()
{
  if (coord.moveY_ != coord.limitYValue_)
    coord.moveY_ -= coord.moveYValue_;
  else
    coord.moveY_ = 0;
}

void			Cursor::moveLeft()
{
  if (coord.moveX_ > 0)
    coord.moveX_ -= coord.moveXValue_;
  else
    coord.moveX_ = coord.limitXValue_;
}

void			Cursor::moveRight()
{
  if (coord.moveX_ != coord.limitXValue_)
    coord.moveX_ += coord.moveXValue_;
  else
    coord.moveX_ = 0;
}

void			Cursor::setChoice()
{
  choice_ = coord.moveY_ / -coord.moveYValue_;
  choice_ = choice_ + 1;
}

unsigned int		Cursor::getChoice()
{
  return (choice_);
}

unsigned int		Cursor::getMoveX()
{
  return (coord.moveX_);
}

unsigned int		Cursor::getMoveY()
{
  return (coord.moveY_);
}

void			Cursor::getBack()
{
  choice_ = 0;
}

void			Cursor::update(Key key)
{
  (this->*fptr_[key])();
  cursor_.update(coord);
  usleep(100000);
}

void			Cursor::draw()
{
  cursor_.draw(coord);
}
